﻿/** \file
* \$Rev: 184 $
* 
* \$Date: 2010-04-14 07:18:41 +0000 (Wed, 14 Apr 2010) $
*
* \$URL: http://chorus-twitter.googlecode.com/svn/trunk/tests/src/TestMergeable.cs $
*/

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using chorus.twitter;
using chorus.utils;

/// <summary>
/// The namespace containing unit tests for Chorus.
/// </summary>
namespace chorus.tests
{
	/// <summary>
	/// A unit test for chorus.utils.Mergeable's behaviour.
	/// </summary>
	[TestClass]
	public class TestMergeable
	{
		/// <summary>The destination object.</summary>
		Account a = new Account();
		/// <summary>The source object.</summary>
		Account b = new Account();

		/// <summary>Initialize the test.</summary>
		[TestInitialize]
		public void Init()
		{
			a.contributors_enabled = new SerStruct<bool>();
			a.contributors_enabled.val = false;
			b.contributors_enabled = new SerStruct<bool>();
			b.contributors_enabled.val = true;

			a.utc_offset = new SerStruct<int>();
			a.utc_offset.val = -100;
			b.utc_offset = new SerStruct<int>();
			b.utc_offset.val = null;

			a.followers_count = new SerStruct<uint>();
			a.followers_count.val = null;
			b.followers_count = new SerStruct<uint>();
			b.followers_count.val = 200;

			a.friends_count = new SerStruct<uint>();
			a.friends_count.val = 300;
			b.friends_count = null;

			a.statuses_count = null;
			b.statuses_count = new SerStruct<uint>();
			b.statuses_count.val = 400;

			a.screen_name = "screen_name a";
			b.screen_name = "screen_name b";

			a.name = "name a";
			b.name = null;

			a.description = null;
			b.description = "description b";
		}

		/// <summary>Test the merging of two non-trivial objects.</summary>
		[TestMethod]
		public void Mergeable()
		{
			a.MergeFrom(b);

			Assert.IsNotNull(a.contributors_enabled);
			Assert.IsNotNull(a.contributors_enabled.val);
			Assert.AreEqual(a.contributors_enabled.val, true);

			Assert.IsNotNull(a.utc_offset);
			Assert.IsNotNull(a.utc_offset.val);
			Assert.AreEqual(a.utc_offset.val, -100);

			Assert.IsNotNull(a.followers_count);
			Assert.IsNotNull(a.followers_count.val);
			Assert.AreEqual(a.followers_count.val, 200u);

			Assert.IsNotNull(a.friends_count);
			Assert.IsNotNull(a.friends_count.val);
			Assert.AreEqual(a.friends_count.val, 300u);

			Assert.IsNotNull(a.statuses_count);
			Assert.IsNotNull(a.statuses_count.val);
			Assert.AreEqual(a.statuses_count.val, 400u);

			Assert.IsNotNull(a.screen_name);
			Assert.AreEqual(a.screen_name, "screen_name b");

			Assert.IsNotNull(a.name);
			Assert.AreEqual(a.name, "name a");

			Assert.IsNotNull(a.description);
			Assert.AreEqual(a.description, "description b");
		}
	}
}
